package cn.da.shuai.cool.system.api.controller;

import cn.da.shuai.cool.common.entity.R;
import cn.da.shuai.cool.system.model.entity.dict.CoolDictType;
import cn.da.shuai.cool.system.service.service.ICoolDictTypeService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 数据字典信息
 */
@RestController
@RequestMapping("/system/dict/type")
@Tag(name = "字典类型控制器")
public class CoolDictTypeController {

    @Autowired
    private ICoolDictTypeService dictTypeService;

    @GetMapping("/list")
    @Operation(summary = "获取字典类型列表")
    public R<List<CoolDictType>> list(CoolDictType dictType) {
        List<CoolDictType> list = dictTypeService.selectDictTypeList(dictType);
        return R.ok(list);
    }

    @GetMapping("/page")
    @Operation(summary = "获取字典类型分页列表")
    public R<Page<CoolDictType>> page(CoolDictType dictType, Page<CoolDictType> page) {
        Page<CoolDictType> list = dictTypeService.selectDictTypePage(dictType, page);
        return R.ok(list);
    }

    @GetMapping("/{dictId}")
    @Operation(summary = "根据字典类型ID获取详细信息")
    public R<CoolDictType> getInfo(@PathVariable Long dictId) {
        return R.ok(dictTypeService.selectDictTypeById(dictId));
    }

    @PostMapping
    @Operation(summary = "新增字典类型")
    public R<Void> add(@RequestBody CoolDictType dict) {
        dictTypeService.insertDictType(dict);
        return R.ok();
    }

    @PutMapping
    @Operation(summary = "修改字典类型")
    public R<Void> edit(@RequestBody CoolDictType dict) {
        dictTypeService.updateDictType(dict);
        return R.ok();
    }

    @DeleteMapping("/{dictIds}")
    @Operation(summary = "删除字典类型")
    public R<Void> remove(@PathVariable Long[] dictIds) {
        dictTypeService.deleteDictTypeByIds(dictIds);
        return R.ok();
    }

    @GetMapping("/refreshCache")
    @Operation(summary = "刷新字典缓存")
    public R<Void> refreshCache() {
        // TODO: 实现刷新字典缓存的逻辑
        return R.ok();
    }

    @GetMapping("/optionselect")
    @Operation(summary = "获取字典选择框列表")
    public R<List<CoolDictType>> optionselect() {
        List<CoolDictType> dictTypes = dictTypeService.selectDictTypeList(new CoolDictType());
        return R.ok(dictTypes);
    }
}